/******************************************************************************
 * FileName:    gwin_general_clock.c
 * Desc:        通用时钟
 *                  判断时钟是否经过指定时间
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

/*-------------------------- Includes ---------------------------------------*/
#include "gwin_board.h"
#include "gwin_general_clock.h"


/*-------------------------- Macro Definitions ------------------------------*/

/*-------------------------- Type Declarations ------------------------------*/

/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
/**
 * @brief 获取时钟
 */
uint32_t gwin_get_general_clock(void)
{
    return (uint32_t)(plt_time_read_ms());
}

/**
 * @brief 判断时钟是否开始
 */
uint8_t gwin_get_general_clock_is_start(const uint32_t *clock)
{
    return (*clock > 0);
}

/**
 * @brief 保存时钟
 */
void gwin_save_general_clock(uint32_t *clock)
{
    *clock = gwin_get_general_clock() | 0x01;
}

/**
 * @brief 清除时钟
 */
void gwin_clear_general_clock(uint32_t *clock)
{
    *clock = 0;
}

/**
 * @brief 判断时钟是否经过指定时间
 */
uint8_t gwin_pass_general_clock(uint32_t clock, uint32_t pass_time_ms)
{
    uint8_t ret = 0;
    uint32_t current = gwin_get_general_clock() | 0x01;
    uint32_t pass = (uint32_t)(current - clock);
    if (gwin_get_general_clock_is_start(&clock) && pass >= pass_time_ms)
    {
        ret = 1;
    }
    return ret;
}


/*-------------------------- END OF FILE ------------------------------------*/

